home *** CD-ROM | disk | FTP | other *** search
/ Aminet 35 / Aminet 35 (2000)(Schatztruhe)[!][Feb 2000].iso / Aminet / game / shoot / ADescentSrc.lha / descent / includes / library.h < prev    next >
C/C++ Source or Header  |  1998-08-08  |  5KB  |  128 lines

  1. /*
  2. THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
  3. SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
  4. END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
  5. ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
  6. IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
  7. SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
  8. FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
  9. CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
  10. AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.  
  11. COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
  12. */
  13.  
  14. #include "cflib.h"
  15. #include "time.h"
  16. #include "types.h"
  17.  
  18. #define USECS_PER_READING( start, stop, frames ) (((stop-start)*54945)/frames)
  19. #define MSECS_TOTAL_TIME( start, stop ) ((stop - start)*55)
  20.  
  21. #define MAX_FILES 500
  22.  
  23. #define ERROR_OPENING_FILE  21
  24. #define ERROR_WRITING_FILE  22
  25. #define ERROR_READING_DATA -20
  26.  
  27. typedef struct bit_file {
  28.     ubyte *buf;
  29.     int current_byte;
  30.     ubyte mask;
  31.     int rack;
  32.     int pacifier_counter;
  33.     int length;
  34. } BIT_BUF;
  35.  
  36. typedef struct lib_header {
  37.    char id[4];      // set to 'PSLB'
  38.    short nfiles;    // how many files in this library
  39. } lib_header;
  40.  
  41. typedef struct file_header {
  42.    char name[13];       // 8 chars, dot, extension, null
  43.    byte compression;    // compression method
  44.    int offset,          // where in the lib file
  45.        length,          // how much space in lib taken by this file
  46.        original_size;   // how long the actual (uncompressed) data is
  47. //   time_t time;         // the date & time, from the time() function
  48.    ushort date;         // the date
  49.    ushort time;         // the time
  50.    short ratio;         // this makes the structure 32 bytes
  51. } file_header;
  52.  
  53. // Date and time macros
  54.  
  55. #define YEAR(t)    (((t & 0xFE00) >> 9) + 1980)
  56. #define MONTH(t)   ((t & 0x01E0) >> 5)
  57. #define DAY(t)     (t & 0x001F)
  58. #define HOUR(t)    ((t & 0xF800) >> 11)
  59. #define MINUTE(t)  ((t & 0x07E0) >> 5)
  60. #define SECOND(t)  ((t & 0x001F) << 1)
  61.  
  62. // bitio function prototypes
  63.  
  64. BIT_BUF *OpenInputBitBuf( ubyte *buffer );
  65. BIT_BUF *OpenOutputBitBuf();
  66. void OutputBit( BIT_BUF *bit_file, int bit );
  67. void OutputBits( BIT_BUF *bit_file, unsigned int code, int count );
  68. int InputBit( BIT_BUF *bit_file );
  69. unsigned int InputBits( BIT_BUF *bit_file, int bit_count );
  70. void CloseInputBitBuf( BIT_BUF *bit_file );
  71. void CloseOutputBitBuf( BIT_BUF *bit_file );
  72. void FilePrintBinary( FILE *file, unsigned int code, int bits );
  73.  
  74. #define LISTING 1       // listing the library
  75. #define BUILDING 1      // building the library
  76. #define LF_LZW 1        // this file has LZW compression
  77.  
  78. #define MAX_FILE_SIZE 1024 * 100
  79.  
  80. // pslib function prototypes
  81.  
  82. int file_size( char *name );
  83. void header_count( char *argv );
  84. int read_data( FILE *fp, struct file_header *p );
  85. void init_library( char *filename, int numfiles );
  86. void write_file_header( char *filename, file_header Header );
  87.  
  88. //void print_usage( void );
  89. //void check_list( char *argv );
  90. //void list_files( void );
  91. //void cfr_test( char *input, char *output );
  92. //void cfw_test( char *input, char *output );
  93. //void extract_test( char *extractname, char *extractout );
  94. //void lib_read_test( char *extractname, char *extractout );
  95. //void process_arg( char *argv );
  96.  
  97.  
  98. extern char *Usage;
  99. extern char *CompressionName;
  100.  
  101. extern int lib_flag;           // library flag
  102. extern int b_flag;             // building flag
  103. extern int c_flag;             // compression flag
  104. extern int l_flag;             // listing flag
  105. extern int lib_flag;           // library flag
  106. extern FILE *InputLibFile;     // file to read from
  107. extern FILE *OutputLibFile;    // file to write to
  108. extern char *lib_name;         // name of the library
  109. extern int file_count;         // number of files processed
  110. extern int headers;            // number of header spaces allocated
  111. extern file_header Header;     // Holds header info of file being processed
  112. extern char *FileList[MAX_FILES];    // Contains the list of files being processed
  113. extern file_header *LibHeaderList;
  114. extern FILE *InputLibInitFile; // file to read from
  115. extern short init_numfiles;    // number of files in the library
  116.  
  117. ubyte *ReadFileRaw( char *filename, int *length );
  118. // ReadFileRaw reads 'filename' and returns the buffer and passes the length
  119. // in bytes.
  120.  
  121. int WriteFile( char *filename, void *data, int length );
  122. // WriteFile writes 'length' bytes of 'data' to 'filename'
  123. //  returns an error code != 0 if there is an error.
  124.  
  125. int AppendFile( char *filename, void *data, int length );
  126. // AppendFile appends 'length' bytes of 'data' to 'filename'
  127. //  returns an error code != 0 if there is an error.
  128.